package com.jk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jk.common.Commonfig;
import com.jk.model.UserBean;
import com.jk.service.SLFService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("slf")
public class SLFController {

    @Reference(check = false)
    private SLFService slfService;




    /**
     * 登录
     * @return
     */
    @RequestMapping("login")
    @ResponseBody
    public Map login(UserBean userBean, HttpServletRequest request){
        HashMap<String, Object> resyIt = new HashMap<>();
        UserBean userInfo= slfService.findUserInfoByAccount(userBean.getUserAccount());
        if (userInfo == null) {
            resyIt.put("code", 2);
            resyIt.put("msg", "账号密码错误");
            return resyIt;
        }
        if (!userInfo.getUserPassword().equals(userBean.getUserPassword())) {
            resyIt.put("code", 3);
            resyIt.put("msg", "账号密码错误");
            return resyIt;
        }
        resyIt.put("code", 0);
        resyIt.put("msg", "登陆成功");
        HttpSession session = request.getSession();
        session.setAttribute(session.getId(),userInfo);
        return resyIt;
    }



}
